<?php
/**
 * Created by PhpStorm
 * User: 龍zero
 * Date: 2022-04-15
 * Time: 9:46
 */

namespace App\Controller\Cms;


use App\Annotation\GroupRequired;
use App\Annotation\Logger;
use App\Annotation\ParamValid;
use App\Annotation\PermissionMeta;
use App\Annotation\PermissionModule;
use App\Controller\AbstractController;
use App\Service\LogService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;

/**
 * @Controller(prefix="cms/log")
 * @PermissionModule(value="日志")
 * Class LogController
 * @package App\Controller\Cms
 */
class LogController extends AbstractController
{

    /**
     * @Inject()
     * @var LogService
     */
    private $logService;

    /**
     * @GetMapping("")
     * @GroupRequired
     * @PermissionMeta(value="查询所有日志")
     * @ParamValid(value={"start","end","count","page"},
     *    rule={"date_format:Y-m-d H:i:s","date_format:Y-m-d H:i:s","min:1|max:30|integer","min:0|integer"})
     */
    public function getLogs(){
        $start = $this->request->input('start');
        $end = $this->request->input('end');
        $name = $this->request->input('name');
        $count = $this->request->input('count',15);
        $page = $this->request->input('page',0);
        return $this->logService->getLogPage($page,$count,$name,$start,$end);
    }

    /**
     * @GetMapping("search")
     * @GroupRequired
     * @PermissionMeta(value="搜索日志")
     * @ParamValid(value={"start","end","count","page"},
     *     rule={"date_format:Y-m-d H:i:s","date_format:Y-m-d H:i:s","min:1|max:30|integer","min:0|integer"})
     */
    public function searchLogs(){
        $start = $this->request->input('start');
        $end = $this->request->input('end');
        $name = $this->request->input('name');
        $keyword = $this->request->input('keyword','');
        $count = $this->request->input('count',15);
        $page = $this->request->input('page',0);
        return $this->logService->searchLogPage($page,$count,$name,$keyword,$start,$end);

    }

    /**
     * @GetMapping("users")
     * @GroupRequired
     * @PermissionMeta(value="查询日志记录的用户")
     * @ParamValid(value={"count","page"},rule={"min:1|max:30|integer","min:0|integer"})
     */
    public function getUsers(){
        $count = $this->request->input('count',10);
        $page = $this->request->input('page',0);
        return $this->logService->getUserNamePage($page,$count);
    }
}